/*
 * Usuario.java
 *
 * Created on October 7, 2007, 10:49 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package petstore.model;

import java.util.Date;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import petstore.util.Util;

/**
 * Entity class Usuario
 * 
 * @author Tom Hayden
 */
@Entity
@Table(name = "usuario")
@AttributeOverrides( {
        @AttributeOverride(name="id", column=@Column(name="cdusuario")),
        @AttributeOverride(name="description", column=@Column(name="dsusuario")),
        @AttributeOverride(name="active", column=@Column(name="ativo"))
    })
public class Usuario extends CodeData {

    @Column(name = "login")
    private String login;

    @Column(name = "senha")
    private String senha;

    @Column(name = "dtexpiracaosenha")
    @Temporal(TemporalType.DATE)
    private Date dataExpiracaoSenha;
    
    @Column(name = "dthrlogonatual")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataHoraLogonAtual;
    
    @Column(name = "dthrultimologon")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataHoraUltimoLogon;

    @ManyToOne
    @JoinColumn(name="cdperfil")
    private Perfil perfil;

    /** Creates a new instance of Usuario */
    public Usuario() {
    }
    
    public boolean isSenhaExpirada() {
        return (this.getDataExpiracaoSenha() == null || Util.today().after(this.getDataExpiracaoSenha()));
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    public Date getDataExpiracaoSenha() {
        return dataExpiracaoSenha;
    }

    public void setDataExpiracaoSenha(Date dataExpiracaoSenha) {
        this.dataExpiracaoSenha = dataExpiracaoSenha;
    }

    public Date getDataHoraLogonAtual() {
        return dataHoraLogonAtual;
    }

    public void setDataHoraLogonAtual(Date dataHoraLogonAtual) {
        this.dataHoraLogonAtual = dataHoraLogonAtual;
    }

    public Date getDataHoraUltimoLogon() {
        return dataHoraUltimoLogon;
    }

    public void setDataHoraUltimoLogon(Date dataHoraUltimoLogon) {
        this.dataHoraUltimoLogon = dataHoraUltimoLogon;
    }

    public Perfil getPerfil() {
        return perfil;
    }

    public void setPerfil(Perfil perfil) {
        this.perfil = perfil;
    }

}
